package net.xconcepts.stockdata.model.analysis;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import net.xconcepts.stockdata.model.analysis.indicator.Indicator;
import net.xconcepts.stockdata.model.analysis.symbol.Symbol;
import net.xconcepts.stockdata.model.tick.SymbolTick;

public class SymbolRule extends Rule<Symbol> {

	Collection<Symbol> mAllowedSymbols = new LinkedList<Symbol>();
	
	public SymbolRule(Collection<Symbol> allowedSymbols) {		
		super(new Indicator<Symbol, Double>() {
			@Override
			protected Symbol processSymbolTick(SymbolTick tick,
					Double baseIndicatorResult) {
				return tick.getSymbol();
			}			
		});
		mAllowedSymbols.addAll(allowedSymbols);
	}

	public SymbolRule(Symbol allowedSymbol) {		
		super(null);
		mAllowedSymbols.add(allowedSymbol);
	}

	@Override
	public Map<Symbol, Boolean> processTicks(Map<Symbol, SymbolTick> ticks) {
		Map<Symbol, Boolean> results = new HashMap<Symbol, Boolean>();
		
		for(Symbol symbol : ticks.keySet()) {
			results.put(symbol, mAllowedSymbols.contains(symbol));
		}
		
		return results;
	}
}
